<template>
    <div>
        <el-input v-model="input" placeholder="请输入内容"></el-input>
        <el-button type="primary" @click="input = ''">清空</el-button>
        <el-button type="primary" @click="init">添加</el-button>
        <div class="length">{{ length }}</div>
    </div>
</template>

<script>
import { Container } from 'element-ui';

export default {
    props: {
        newlength: {
            type: Number,
            default: 0
        }
    },
    data() {
        return {
            input: "",
            container: [],
            length:0,
        }
    },
    methods: {
        init() {
            if (this.input.trim()) {
                this.container.push(this.input);
                this.input = "";
                this.$emit("init", this.container);
                this.length = this.container.length;
            }
        }
    },
    watch: {
        newlength(newValue) {
            this.length = newValue;
        }
    },
}
</script>

<style></style>